<?php

// +----------------------------------------------------------------------
// | 加载首页数据
// +----------------------------------------------------------------------
// | Copyright (c) 2015-2024 http://www.yicmf.com, All rights reserved.
// +----------------------------------------------------------------------
// | Author: 微尘 <yicmf@qq.com>
// +----------------------------------------------------------------------

namespace app\controller\pos\admin;


use app\controller\admin\Common;
use app\model\im\ChatContent as ChatContentModel;
use app\model\im\Chat as ChatModel;
use app\model\ucenter\User as UserModel;

class Home extends Common
{

    public function overview()
    {

        $number = \app\model\pos\PosOrder::where('status', 2)->count();
        $overview[] = [
            'title' => '未处理订单',
            'number' => $number,
        ];
        return $overview;
    }

    public function left()
    {
        return;
        $show_day = 6;
        $content = ChatContentModel::field('DATE_FORMAT(create_time,"%Y%m%d") days,count(id)  num')->whereTime('create_time', date('Y-m-d', strtotime('-'.$show_day.' days')))->group('days')->select();
        $chats = ChatModel::field('DATE_FORMAT(create_time,"%Y%m%d") days,count(id)  num')->whereTime('create_time', date('Y-m-d', strtotime('-'.$show_day.' days')))->group('days')->select();
        $evaluates = \app\model\im\Evaluate::field('DATE_FORMAT(create_time,"%Y%m%d") days,count(id)  num')->whereTime('create_time', date('Y-m-d', strtotime('-'.$show_day.' days')))->group('days')->select();
//            $result = UserModel::field('DATE_FORMAT(create_time,"%Y%m%d") days,count(id)  num')->whereTime('create_time', date('Y-m-d', strtotime('-7 days')))->group('days')->select();
//            $result2 = UserModel::where('status', 5)
//                ->field('DATE_FORMAT(last_active_time,"%Y%m%d") days,count(id)  num')->whereTime('last_active_time', date('Y-m-d', strtotime('-7 days')))->group('days')->select();
        $x_time = [];
        $series1 = [];
        $series2 = [];
        $series3 = [];
        for ($i = $show_day; $i >= 0; $i--) {
            $day = date('Ymd', strtotime(date('Y-m-d', strtotime('-' . $i . ' days'))));
            $num = 0;
            $x_time[] = $day;
            foreach ($content as $item) {
                if ($item['days'] == $day) {
                    $num = $item['num'];
                    break;
                }
            }
            $series1[] = $num;
            $num = 0;
            foreach ($chats as $item) {
                if ($item['days'] == $day) {
                    $num = $item['num'];
                    break;
                }
            }
            $series2[] = $num;
            $num = 0;
            foreach ($evaluates as $item) {
                if ($item['days'] == $day) {
                    $num = $item['num'];
                    break;
                }
            }
            $series3[] = $num;
        }
        $this->assign('x_time', $x_time);
        $this->assign('show_day', $show_day);
        $this->assign('series1', $series1);
        $this->assign('series2', $series2);
        $this->assign('series3', $series3);

        // 显示页面
        return $this->fetch('pos/admin/home/left');
    }

    public function right()
    {
        // 显示页面
        return $this->fetch('pos/admin/home/right');
    }

    /**
     * 快捷方式
     * @return array
     */
    public function quick()
    {
        return [];
    }

    /**
     * 待办事项
     * @return array
     */
    public function wait()
    {

//            'title' => $item['title'],
//                            'num' => $item['number'],
//                            'create_time' => time_format(),
//                            'action' => $item['link'],
        $number = \app\model\pos\PosOrder::where('status', 2)->count();
        $wait[] = [
            'title'=>'发货',
            'number'=>$number,
            'link'=>'pos/admin/PosOrder/index?status=2',
        ];
        return $wait;
    }

    public function chart()
    {
        return '';
        // 显示页面
        return $this->fetch('pos/admin/home/chart');
    }

}
